#ifndef THREAD_H_
#define THREAD_H_

#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <ucontext.h>
#include <valgrind/valgrind.h>
#include <signal.h>
#include <sys/mman.h>
#include <unistd.h>
#include <malloc.h>
#include <sys/time.h>

#define DEFAULT_PRIO 20

#define TIME_SLICE 50

#define NB_SIG 6
#define SIG_WAKE -1
#define SIG_YIELD 0
#define SIG_KILL 1
#define SIG_USR1 2
#define SIG_USR2 3
#define SIG_USR3 4
#define SIG_USR4 5

typedef void(*func_sig)(int);

struct Thread {
  ucontext_t * contexte;

  void * (*func) (void*);
  void * arg;
  void * resultat;

  int priorite;
  int priorite_actuelle;

  int ID;
  int termine;

  func_sig fonctions_sig[NB_SIG];;
  GList * signal_attente;

  int valgrind_stackid;
};

typedef struct Thread* Thread;
typedef Thread thread_t;

Thread thread_self (void);
int thread_create (Thread *, void *(* func)(void *), void *);
int thread_create_prio (Thread *, void *(* func)(void *), void *, int);
void thread_start (Thread);
int thread_yield (void);
int thread_join (Thread, void **);
void thread_exit (void *);

//Non fonctionnel
void thread_kill (Thread, int);
void thread_signal_alloc (Thread, int, void (*)(int));
void thread_signal_treat (Thread);

#endif
